import 'package:dio/dio.dart';
import 'package:fsharing/core/services/api.dart';
import 'package:fsharing/core/viewmodels/view_model.dart';

/// 地址删除
class AddressDeleteModel extends ViewModel {
  final Api api;
  String _errorMessage;

  AddressDeleteModel(this.api) : super();

  String get errorMessage => _errorMessage;

  Future<ViewState> addressDelete(int addressId) async {
    viewState = ViewState.busy;
    try {
      await api.addressDelete(addressId);
      viewState = ViewState.success;
    } catch (e) {
      _errorMessage = e is DioError ? e.message : e.toString();
      viewState = ViewState.error;
    }
    return viewState;
  }
}
